+2005-08-25 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-classes.h:
+ BablFormat: added .bytes_per_pixel
+ BablImage: s/bands/components/
+ * babl/babl-conversion.c: s/bands/components/
+ * babl/babl-image.c: s/bands/components/
+ * babl/babl-pixel-format.c: (format_new) check if provided pixel
+ format matches model. Calculate .bytes_per_pixel.
+
2005-08-25 Øyvind Kolås <pippin@gimp.org>
* babl/babl-classes.h:
BablType **type;
BablSampling **sampling;
BablModel *model;
+ int bytes_per_pixel;
int planar;
} BablFormat;
BablInstance instance;
BablFormat *format; /*< (if known) */
BablModel *model; /*< (always known) */
- int bands;
+ int components;
BablComponent **component;
BablSampling **sampling;
BablType **type;
{
Babl *babl;
+ {
+ int i;
+ /* i is desintation position */
+ for (i=0 ; i<model->components; i++)
+ {
+ int j;
+
+ for (j=0;j<components;j++)
+ {
+ if (component[j] == model->component[i])
+ goto component_found;
+ }
+ babl_log ("%s(): matching source component for %s in model %s not found",
+ __FUNCTION__,
+ model->component[i]->instance.name, model->instance.name);
+ exit (-1);
+ component_found:
+ ;
+ }
+ }
+
/* allocate all memory in one chunk */
babl = babl_malloc (sizeof (BablFormat) +
strlen (name) + 1 +
sizeof (int) * (components) +
sizeof (int) * (components));
+ babl->format.from = NULL;
+ babl->format.to = NULL;
babl->format.component = ((void *)babl) + sizeof (BablFormat);
babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (components);
babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (components);
- babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components);
+ babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components);
babl->class_type = BABL_FORMAT;
babl->instance.id = id;
strcpy (babl->instance.name, name);
+
babl->format.model = model;
babl->format.components = components;
- babl->format.planar = planar;
memcpy (babl->format.component, component, sizeof (BablComponent*) * components);
memcpy (babl->format.type , type , sizeof (BablType*) * components);
memcpy (babl->format.sampling , sampling , sizeof (BablSampling*) * components);
- babl->format.from = NULL;
- babl->format.to = NULL;
+ babl->format.planar = planar;
+
+ babl->format.bytes_per_pixel = 0;
+ {
+ int i;
+ for (i=0;i<components;i++)
+ babl->format.bytes_per_pixel += type[i]->bits/8;
+ }
return babl;
}
static Babl *
image_new (BablFormat *format,
BablModel *model,
- int bands,
+ int components,
BablComponent **component,
BablSampling **sampling,
BablType **type,
/* allocate all memory in one chunk */
babl = babl_malloc (sizeof (BablImage) +
- sizeof (BablComponent*) * (bands) +
- sizeof (BablSampling*) * (bands) +
- sizeof (BablType*) * (bands) +
- sizeof (void*) * (bands) +
- sizeof (int) * (bands) +
- sizeof (int) * (bands));
+ sizeof (BablComponent*) * (components) +
+ sizeof (BablSampling*) * (components) +
+ sizeof (BablType*) * (components) +
+ sizeof (void*) * (components) +
+ sizeof (int) * (components) +
+ sizeof (int) * (components));
babl->image.component = ((void *)babl) + sizeof (BablImage);
- babl->image.sampling = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands);
- babl->image.type = ((void *)babl->image.sampling) + sizeof (BablSampling*) * (bands);
- babl->image.data = ((void *)babl->image.type) + sizeof (BablType*) * (bands);
- babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (bands);
- babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (bands);
-
- babl->class_type = BABL_IMAGE;
- babl->instance.id = 0;
- babl->instance.name = "slaritbartfast";
-
- babl->image.format = format;
- babl->image.model = model;
- babl->image.bands = bands;
- memcpy (babl->image.component, component, bands * sizeof(void*));
- memcpy (babl->image.type, type, bands * sizeof(void*));
- memcpy (babl->image.data, data, bands * sizeof(void*));
- memcpy (babl->image.pitch, pitch, bands * sizeof(int));
- memcpy (babl->image.stride, stride, bands * sizeof(int));
+ babl->image.sampling = ((void *)babl->image.component) + sizeof (BablComponent*) * (components);
+ babl->image.type = ((void *)babl->image.sampling) + sizeof (BablSampling*) * (components);
+ babl->image.data = ((void *)babl->image.type) + sizeof (BablType*) * (components);
+ babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (components);
+ babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (components);
+
+ babl->class_type = BABL_IMAGE;
+ babl->instance.id = 0;
+ babl->instance.name = "slaritbartfast";
+ babl->image.format = format;
+ babl->image.model = model;
+ babl->image.components = components;
+
+ memcpy (babl->image.component, component, components * sizeof(void*));
+ memcpy (babl->image.type, type, components * sizeof(void*));
+ memcpy (babl->image.data, data, components * sizeof(void*));
+ memcpy (babl->image.pitch, pitch, components * sizeof(int));
+ memcpy (babl->image.stride, stride, components * sizeof(int));
return babl;
}
{
va_list varg;
Babl *babl;
- int components = 0;
+ int components= 0;
BablFormat *format = NULL;
BablModel *model = NULL;
BablComponent *component [BABL_MAX_COMPONENTS];
{
Babl *babl;
+ {
+ int i;
+ /* i is desintation position */
+ for (i=0 ; i<model->components; i++)
+ {
+ int j;
+
+ for (j=0;j<components;j++)
+ {
+ if (component[j] == model->component[i])
+ goto component_found;
+ }
+ babl_log ("%s(): matching source component for %s in model %s not found",
+ __FUNCTION__,
+ model->component[i]->instance.name, model->instance.name);
+ exit (-1);
+ component_found:
+ ;
+ }
+ }
+
/* allocate all memory in one chunk */
babl = babl_malloc (sizeof (BablFormat) +
strlen (name) + 1 +
sizeof (int) * (components) +
sizeof (int) * (components));
+ babl->format.from = NULL;
+ babl->format.to = NULL;
babl->format.component = ((void *)babl) + sizeof (BablFormat);
babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (components);
babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (components);
- babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components);
+ babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components);
babl->class_type = BABL_FORMAT;
babl->instance.id = id;
strcpy (babl->instance.name, name);
+
babl->format.model = model;
babl->format.components = components;
- babl->format.planar = planar;
memcpy (babl->format.component, component, sizeof (BablComponent*) * components);
memcpy (babl->format.type , type , sizeof (BablType*) * components);
memcpy (babl->format.sampling , sampling , sizeof (BablSampling*) * components);
- babl->format.from = NULL;
- babl->format.to = NULL;
+ babl->format.planar = planar;
+
+ babl->format.bytes_per_pixel = 0;
+ {
+ int i;
+ for (i=0;i<components;i++)
+ babl->format.bytes_per_pixel += type[i]->bits/8;
+ }
return babl;
}